package approve.service;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.TimerTask;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import approve.action.App_NotApproveDocument;
import approve.action.LoginActivity;
import approve.action.MainEApproval;
import approve.action.R;

public class DoService extends Service{

	private static final String TAG = "DoService";
	
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
	@Override
	public void onCreate() {
		Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onCreate");
		
	}

	@Override
	public void onDestroy() {
		Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onDestroy");
	}
	
	@Override
	public void onStart(Intent intent, int startid) {
		Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onStart");
	}
	
	private class mainTask extends TimerTask {
		@Override
		public void run() {
//			try{
//				Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
//				Date currentLocalTime = cal.getTime();
//				System.out.println("zone: "+TimeZone.getDefault().getDisplayName()+" -- "+TimeZone.getDefault().getID()+" --- "+currentLocalTime.getHours());
//				if(currentLocalTime.getHours()>=8 && currentLocalTime.getHours()<=22){
//					if(LoginActivity.flagruntimer==false){
//						final Notification notifyDetails;
//						int count=rd.countAllNewMessage(LoginActivity.emp.getIdemployee(), LoginActivity.database);
//						if(count>0){
//							if(LoginActivity.soluong<count){
//								LoginActivity.soluong=count;
//								notifyDetails = new Notification(R.drawable.mail,count + " new message", System.currentTimeMillis());
//								notifyDetails.defaults = Notification.DEFAULT_ALL;
//								Context context = getApplicationContext();
//								CharSequence contentTitle = "You have " + LoginActivity.soluong + " new message";
//								CharSequence contentText = "click me to view detail";
//								Intent notifyIntent = new Intent(getApplicationContext(),App_NotApproveDocument.class);
//								PendingIntent intent = PendingIntent.getActivity(getApplicationContext(),0, notifyIntent,android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
//								notifyDetails.setLatestEventInfo(context, contentTitle,contentText, intent);
//								mNotificationManager.notify(SIMPLE_NOTFICATION_ID,notifyDetails);
//							}else{
//								LoginActivity.soluong=count;
//							}
//						}else{
//							if(LoginActivity.soluong!=0){
//								LoginActivity.soluong=0;
//								mNotificationManager.cancel(MainEApproval.SIMPLE_NOTFICATION_ID);
//							}
//						}
//					}else{
//						LoginActivity.soluong=0;
//						mNotificationManager.cancel(MainEApproval.SIMPLE_NOTFICATION_ID);
//						timer.cancel();
//					}
//				}else{
//					LoginActivity.soluong=0;
//					mNotificationManager.cancel(MainEApproval.SIMPLE_NOTFICATION_ID);
//					timer.cancel();
//				}
//				
//				
//			}catch(Exception e){
//				MainEApproval.this.writelog(e.getMessage());
//			}
			
		}
	}

}
